<?php

namespace App\Http\Controllers\Chanjet;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Fee\FeeTypeController;
use App\Models\Fee\FeeType;
use Illuminate\Http\Request;

class TplusExpenseVoucher extends BaseController
{
    public function getExternalData(Request $request){
        $common = new TplusCommonController();
        $res = $common->getExternalData("TplusExpenseVoucher",$this->mangerinfo['org_id']);
        return $res;
    }

    public function getlist(Request $request)
    {
        $memberinfo = $this->mangerinfo;
        $isgetall = $request->isgetall ?? 0;
        $list = \App\Models\Chanjet\TplusExpenseVoucher::getList($request, $memberinfo, $isgetall);

        //费用类型返回
        if(isset($list)){
            foreach ($list['list'] as $key => $item) {
                foreach ($item['info'] as $key2 => $item2) {
                    $expense_code_arr = explode('_',$item2['expense_code']);
                    if(count($expense_code_arr) !== 3){
                        continue;
                    }else{
                        $category = FeeType::where('id',$expense_code_arr[2])->value('category');
                        if(!$category){
                            continue;
                        }
                        $categoryName = FeeTypeController::$feeTypeCategory[$category];
                        $list['list'][$key]['info'][$key2]['expense_type'] = $categoryName;
                    }
                }
            }
        }
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }
}
